package com.zhengyao.webfilter;

import com.zhengyao.threadlocal.WebConfig;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author : zhengyao3@郑瑶
 * @date : 2020/7/24 11:20
 * @Description: 设置dubbo的IP过滤器
 */
@WebFilter(urlPatterns = "/*", filterName = "DubboWebGetIpFilter")
public class DubboWebGetIpFilter implements Filter {
    
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String remoteAddr = request.getRemoteAddr();
        String remoteHost = request.getRemoteHost();
        System.out.println(remoteHost);
        System.out.println(remoteAddr);
        WebConfig.setThreadLocalIp(remoteAddr);
        chain.doFilter(request,response);
    }
}
